import { PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn } from "typeorm";

import { ExtIdTuple, ExtOwner, VARCHAR50_PG, BIGINT_PG, User, ExtBigIdTuple } from "qqlx-core";

import { TransformerBigInteger } from "@lib/orm.transfor.number";
import { TransformerVarchar50 } from "@lib/orm.transfor.string";
import { TransformerBoolean } from "@lib/orm.transfor.boolean";

import { NotFunction } from "@/alpha/ext.base";

export class JustIdSchema extends NotFunction implements ExtIdTuple {
  @PrimaryGeneratedColumn({ type: "integer" })
  id!: number;

  @Column({ transformer: new TransformerBoolean(), type: "boolean", nullable: false })
  isDisabled: boolean = false;

  @Column({ transformer: new TransformerBigInteger(), type: "bigint", nullable: false })
  timeCreate: BIGINT_PG = Date.now().toString();

  @Column({ transformer: new TransformerBigInteger(), type: "bigint", nullable: false })
  timeUpdate: BIGINT_PG = Date.now().toString();
}

export class OwnerIdSchema extends JustIdSchema implements ExtOwner {
  @Column({ transformer: new TransformerVarchar50() })
  refOwnerUUid32!: VARCHAR50_PG;

  // ======= JOIN =======
  // ======= JOIN =======
  // ======= JOIN =======

  @ManyToOne("UserSchema")
  @JoinColumn({ name: "refOwnerUUid32", referencedColumnName: "uuid32" })
  justOwner!: User;
}
